/*
 * @Author: Quinn
 * @Date: 2023-05-18 11:31:42
 * @LastEditors: quinn
 * @Description:
 */
import store from "@/store/index";
import { LOGIN_PATH } from "@/assets/js/define";

const extender = (router) => {
  router.cacheRouter = [];
  router.beforeEach((to, from, next) => {
    const tokenv3 =
      store.state.tokenv3 || window.$quinn.getStorage("tokenv3") || "";
    const userData =
      window.$quinn.getStorage("userDatav3") || store.state.userData || {};
    if (!tokenv3) window.location.href = LOGIN_PATH;
    else
      store.commit("modify", {
        tokenv3,
        userData,
      });
    const cacheRouter = store.state.cacheRouter;
   
    //取消  routerArray 页面的kepplive缓存 否则销售订单驳回后 页面不刷新
    // const routerArray = ['UserOrder','ProcureList','SaleList','MaterialList','InventoryInventoryList']
    // && !routerArray.includes(to.name)
    if (cacheRouter.every((e) => e.name !== to.name) ) {
      cacheRouter.push(to);
      store.commit("modify", {
        cacheRouter,
      });
    }
    next();
  });
  return router;
};

export default extender;
